home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / text / proged1.lha / InstallProgED / SASC_support / Sources / GetProjectDir.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  3KB  |  159 lines

  1.  
  2. #include <proto/dos.h>
  3. #include <proto/exec.h>
  4. #include <proto/rexxsyslib.h>
  5. #include <rexx/errors.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. struct Library    *RexxSysBase;
  10.  
  11. /*****
  12.  *
  13.  * FUNZIONE:    ULONG *SendRexxCommand(char *port,char *cmd,struct MsgPort *replyPort,char *buffer)
  14.  *
  15.  * SCOPO:    Manda un messaggio "cmd" AREXX alla porta "port" utilizzando una
  16.  *        porta di reply "replyport".Al termine in "buffer" (se !=NULL)
  17.  *        viene copiato il Result2 del messaggio.
  18.  *
  19.  * RESTITUISCE:    NULL=host non trovato, altrimenti puntatore a LONG indicante il Result1 del mess.
  20.  *
  21.  ****/
  22.  
  23. ULONG *SendRexxCommand(char *port,char *cmd,struct MsgPort *replyPort,char *buffer)
  24. {
  25.     struct MsgPort    *rexxport;
  26.  
  27.  
  28.  
  29.     Forbid();
  30.  
  31.     if (rexxport=FindPort(port))
  32.     {
  33.         struct RexxMsg    *rexxMsg,
  34.                 *answer;
  35.  
  36.         if (rexxMsg=CreateRexxMsg(replyPort,NULL,NULL))
  37.         {
  38.             if (rexxMsg->rm_Args[0]=CreateArgstring(cmd,strlen(cmd)))
  39.             {
  40.                 static ULONG result;
  41.  
  42.                 rexxMsg->rm_Action=RXCOMM|RXFF_RESULT;
  43.  
  44.                 PutMsg(rexxport,&rexxMsg->rm_Node);
  45.  
  46.                 do
  47.                 {
  48.                     WaitPort(replyPort);
  49.                     if (answer=(struct RexxMsg *)GetMsg(replyPort))    result=answer->rm_Result1;
  50.  
  51.                 }
  52.                 while(!answer);
  53.  
  54.                 Permit();
  55.  
  56.                 if (answer->rm_Result1==RC_OK)
  57.                 {
  58.                     if (answer->rm_Result2)
  59.                     {
  60.                         if (buffer)    strcpy(buffer,(char *)answer->rm_Result2);
  61.                         DeleteArgstring((char *)answer->rm_Result2);
  62.                     }
  63.                 }
  64.  
  65.                 DeleteArgstring((char *)ARG0(answer));
  66.  
  67.                 DeleteRexxMsg(answer);
  68.  
  69.                 return(&result);
  70.             }
  71.         }
  72.     }
  73.  
  74.     Permit();
  75.  
  76.     return(NULL);
  77. }
  78.  
  79.  
  80.  
  81. /*****
  82.  *
  83.  * FUNZIONE:    void Split(char *str1,char *str2)
  84.  *
  85.  * SCOPO:    Splitta il nome file in str1 in directory (restituito in str1)
  86.  *        e file (restituito in str2).
  87.  *
  88.  * RESTITUISCE: -
  89.  *
  90.  ****/
  91.  
  92. void Split(char *str1,char *str2)
  93. {
  94.     int    l=strlen(str1);
  95.     do l--;
  96.     while((l>=0)&&(str1[l]!='/')&&(str1[l]!=':'));
  97.     if (l<0) *str2=0;
  98.     else
  99.     {
  100.         strcpy(str2,str1);
  101.         str2[l+1]=0;
  102.         strcpy(str1,str1+l+1);
  103.     }
  104. }
  105.  
  106.  
  107.  
  108. /*********
  109.  *
  110.  * MAIN
  111.  *
  112.  *********/
  113.  
  114. void main(int argc,char *argv[])
  115. {
  116.     struct MsgPort    *ReplyPort;
  117.     int         num;
  118.     char        **vet,
  119.              file[200],
  120.              buffer[200];
  121.  
  122.  
  123.     SetVar("PROJDIR","",-1,GVF_LOCAL_ONLY);
  124.  
  125.     if (!(RexxSysBase=OpenLibrary("rexxsyslib.library",0)))    exit(5);
  126.  
  127.     if (!(ReplyPort=CreateMsgPort()))
  128.     {
  129.         CloseLibrary(RexxSysBase);
  130.         exit(5);
  131.     }
  132.  
  133.     SendRexxCommand("PED_AREXX","GUI LOCK",ReplyPort,buffer);
  134.  
  135.     SendRexxCommand("PED_AREXX","QUERY NUMPROJECTFILES",ReplyPort,buffer);
  136.  
  137.     num=atol(buffer);
  138.  
  139.     SendRexxCommand("PED_AREXX","QUERY ADDPROJECTFILES",ReplyPort,buffer);
  140.  
  141.     vet=(char **)atol(buffer);
  142.  
  143.     if (num>0)    strcpy(file,vet[0]);
  144.  
  145.     SendRexxCommand("PED_AREXX","GUI UNLOCK",ReplyPort,buffer);
  146.  
  147.     DeleteMsgPort(ReplyPort);
  148.  
  149.     CloseLibrary(RexxSysBase);
  150.  
  151.     if (num<=0)    exit(5);
  152.  
  153.     Split(file,buffer);
  154.  
  155.     SetVar("PROJDIR",buffer,-1,GVF_LOCAL_ONLY);
  156.  
  157.     exit(0);
  158. }
  159.